#!/usr/bin/env node

var buf1 = Buffer(256);
buf1[0] = 0;
console.log(buf1.length);
console.log(buf1);
for(var i = 0; i<256; i++){
    buf1[i] = i
;
}console.log(buf1);

//切片
var buf2 = buf1.slice(246,256)
console.log(buf2,buf2.length)

var buf3Array = [1,2,3,4,5]
var buf3 =  Buffer(buf3Array);
console.log(buf3,buf3.length)

var buf4 = Buffer ('hello world','utf8');
console.log(buf4,buf4.length);

buf4.copy(buf3,0,0,buf4.length);
console.log(buf3.length,buf3.toString());

//数组123，实例化一个buffer对象
const buffer123 = Buffer.from([1,2,3]);
console.log(buffer123)

const bufferU8 = Buffer.from('hello, 你好','utf8');
console.log('utf8:',bufferU8);
const bufferU16 = Buffer.from('hello, 你好','utf16le');
console.log('utf16:',bufferU16);
const bufferBase64 = Buffer.from('hello, 你好','base64');
console.log('base64:',bufferBase64);